<?php

namespace addons\kzvote\controller\store;

use app\common\model\kzvote\music\Music;
use app\common\model\kzvote\Option;
use app\common\model\kzvote\Vote as VoteModel;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Vote extends BaseController
{

    /**
     * 查看
     */
    public function index()
    {
        $user = $this->auth->getUser();
        if ($this->request->isAjax()) {
            $params = $this->request->param();
            $where = [];
            if ($params['mold']){
                $where['mold'] = $params['mold'];
            }
            if ($params['check'] || $params['check'] === '0'){
                $where['check'] = $params['check'];
            }
            if ($params['status']){
                $where['status'] = $params['status'];
            }
            if ($params['name']){
                $where['name'] = ['like',"%{$params['name']}%"];
            }

            $list = VoteModel::where('user_id', $user['id'])
                ->where('status','<',30)
                ->where($where)
                ->order('id desc')
                ->paginate(10);

            $result = array("total" => $list->total(), "rows" => $list->items());
            $this->success('','',$result);
        }
        $temp  = VoteModel::where(['status' => '10', 'check' => 1, 'is_temp' => 1])
            ->field('name, image, temp_name')
            ->select();
        $music = Music::where('status', '10')
            ->order('weigh', 'desc')
            ->field('id,name')
            ->select();
        $option = Option::order('weigh desc')->column('name');
        $this->view->assign('temp', $temp);
        $this->view->assign('music', $music);
        $this->view->assign('option', $option);
        return $this->view->fetch();
    }

    /**
     * 查询投票活动主数据
     */
    public function detail()
    {
        $vote_id = $this->request->param('vote_id');
        $detail  = VoteModel::get($vote_id);
        $this->success('','',$detail);
    }


}
